﻿using MySchool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyKTV
{
    public partial class Form2 : Form
    {
        DBHelper db = new DBHelper();
        DataSet ds = new DataSet();
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            db.OpenConnection();
            string str = "select resource_path from resource_path where resource_id=1";
            SqlCommand comm = new SqlCommand(str, db.Connection);

            SqlDataReader reader = comm.ExecuteReader();

            while (reader.Read())
            {

                this.textBoxEx1.Text = reader["resource_path"].ToString();

            }
            reader.Close();
            db.CloseConnection();
        }

        private void btn_liu_Click(object sender, EventArgs e)
        {

            FolderBrowserDialog folder = new FolderBrowserDialog();
            DialogResult result = folder.ShowDialog();
            //Directory返回文件内容，GetFiles返回多个文件
            string[] files = Directory.GetFiles(this.textBoxEx1.Text);
            foreach (var file in files)
            {

                //substring为了获取文件名
                string fileName = file.Substring(file.LastIndexOf("\\") + 1);
                //Copy复制只能实现一个文件到另一个文件中，两个参数第一个文件，第二个目标路径
                File.Copy(file, folder.SelectedPath + "\\" + fileName);
            }
            this.textBoxEx2.Text = folder.SelectedPath;
            this.textBoxEx2.ReadOnly = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            db.OpenConnection();

            string str = "update resource_path set resource_path=N'" + this.textBoxEx2.Text + "' where resource_id=1";
            SqlCommand comm = new SqlCommand(str, db.Connection);
            int iret = comm.ExecuteNonQuery();

            if (iret > 0)
            {
                MessageBox.Show("修改成功！");

            }
            else
            {
                MessageBox.Show("修改失败！");
            }
            db.CloseConnection();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            FolderBrowserDialog folder = new FolderBrowserDialog();
            DialogResult result = folder.ShowDialog();


            //Directory返回文件内容，GetFiles返回多个文件
            string[] files = Directory.GetFiles(this.textBoxEx1.Text);
            foreach (var file in files)
            {

                //substring为了获取文件名
                string fileName = file.Substring(file.LastIndexOf("\\") + 1);
                //Copy复制只能实现一个文件到另一个文件中，两个参数第一个文件，第二个目标路径
                File.Copy(file, folder.SelectedPath + "\\" + fileName);
            }
            this.textBoxEx2.Text = folder.SelectedPath;
            this.textBoxEx2.ReadOnly = true;
        }
    }
}
